from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-28 14:12:12.567713
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 28, Aug, 2021
Time: 14:12:17
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.8369
Nobs: 397.000 HQIC: -46.3823
Log likelihood: 4298.03 FPE: 5.02464e-21
AIC: -46.7400 Det(Omega_mle): 4.01671e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.434927 0.094880 4.584 0.000
L1.Burgenland 0.102403 0.049005 2.090 0.037
L1.Kärnten -0.115744 0.024383 -4.747 0.000
L1.Niederösterreich 0.160929 0.105456 1.526 0.127
L1.Oberösterreich 0.136902 0.103704 1.320 0.187
L1.Salzburg 0.281544 0.051384 5.479 0.000
L1.Steiermark 0.025152 0.068163 0.369 0.712
L1.Tirol 0.109964 0.053754 2.046 0.041
L1.Vorarlberg -0.115801 0.048650 -2.380 0.017
L1.Wien -0.013551 0.093559 -0.145 0.885
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.020960 0.220392 0.095 0.924
L1.Burgenland -0.044575 0.113832 -0.392 0.695
L1.Kärnten 0.036192 0.056639 0.639 0.523
L1.Niederösterreich -0.250857 0.244957 -1.024 0.306
L1.Oberösterreich 0.531915 0.240890 2.208 0.027
L1.Salzburg 0.310905 0.119356 2.605 0.009
L1.Steiermark 0.114899 0.158332 0.726 0.468
L1.Tirol 0.307499 0.124862 2.463 0.014
L1.Vorarlberg -0.008677 0.113007 -0.077 0.939
L1.Wien -0.006762 0.217323 -0.031 0.975
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.253635 0.048442 5.236 0.000
L1.Burgenland 0.087449 0.025020 3.495 0.000
L1.Kärnten -0.002151 0.012449 -0.173 0.863
L1.Niederösterreich 0.210571 0.053841 3.911 0.000
L1.Oberösterreich 0.170991 0.052947 3.229 0.001
L1.Salzburg 0.038075 0.026234 1.451 0.147
L1.Steiermark 0.015494 0.034801 0.445 0.656
L1.Tirol 0.062087 0.027444 2.262 0.024
L1.Vorarlberg 0.059337 0.024839 2.389 0.017
L1.Wien 0.105693 0.047767 2.213 0.027
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181223 0.047113 3.847 0.000
L1.Burgenland 0.045736 0.024334 1.880 0.060
L1.Kärnten -0.007291 0.012107 -0.602 0.547
L1.Niederösterreich 0.134143 0.052364 2.562 0.010
L1.Oberösterreich 0.316397 0.051494 6.144 0.000
L1.Salzburg 0.098861 0.025514 3.875 0.000
L1.Steiermark 0.137426 0.033846 4.060 0.000
L1.Tirol 0.075091 0.026691 2.813 0.005
L1.Vorarlberg 0.054710 0.024157 2.265 0.024
L1.Wien -0.036755 0.046456 -0.791 0.429
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209763 0.093861 2.235 0.025
L1.Burgenland -0.061242 0.048479 -1.263 0.206
L1.Kärnten -0.035882 0.024121 -1.488 0.137
L1.Niederösterreich 0.117736 0.104322 1.129 0.259
L1.Oberösterreich 0.182157 0.102590 1.776 0.076
L1.Salzburg 0.258456 0.050831 5.085 0.000
L1.Steiermark 0.078448 0.067430 1.163 0.245
L1.Tirol 0.123534 0.053176 2.323 0.020
L1.Vorarlberg 0.111113 0.048127 2.309 0.021
L1.Wien 0.020017 0.092553 0.216 0.829
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.024146 0.073046 0.331 0.741
L1.Burgenland 0.026030 0.037728 0.690 0.490
L1.Kärnten 0.050768 0.018772 2.704 0.007
L1.Niederösterreich 0.209468 0.081188 2.580 0.010
L1.Oberösterreich 0.341408 0.079840 4.276 0.000
L1.Salzburg 0.046329 0.039559 1.171 0.242
L1.Steiermark -0.001937 0.052477 -0.037 0.971
L1.Tirol 0.114359 0.041384 2.763 0.006
L1.Vorarlberg 0.061053 0.037455 1.630 0.103
L1.Wien 0.129537 0.072029 1.798 0.072
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189272 0.089066 2.125 0.034
L1.Burgenland 0.019327 0.046003 0.420 0.674
L1.Kärnten -0.057152 0.022889 -2.497 0.013
L1.Niederösterreich -0.134957 0.098994 -1.363 0.173
L1.Oberösterreich 0.197994 0.097350 2.034 0.042
L1.Salzburg 0.028717 0.048235 0.595 0.552
L1.Steiermark 0.303379 0.063986 4.741 0.000
L1.Tirol 0.491111 0.050460 9.733 0.000
L1.Vorarlberg 0.067690 0.045669 1.482 0.138
L1.Wien -0.102561 0.087826 -1.168 0.243
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160052 0.096968 1.651 0.099
L1.Burgenland -0.004351 0.050084 -0.087 0.931
L1.Kärnten 0.063517 0.024920 2.549 0.011
L1.Niederösterreich 0.203746 0.107776 1.890 0.059
L1.Oberösterreich -0.119976 0.105986 -1.132 0.258
L1.Salzburg 0.242244 0.052514 4.613 0.000
L1.Steiermark 0.151767 0.069662 2.179 0.029
L1.Tirol 0.049910 0.054936 0.909 0.364
L1.Vorarlberg 0.121012 0.049720 2.434 0.015
L1.Wien 0.135233 0.095617 1.414 0.157
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.486245 0.052590 9.246 0.000
L1.Burgenland -0.011470 0.027162 -0.422 0.673
L1.Kärnten -0.010467 0.013515 -0.775 0.439
L1.Niederösterreich 0.202753 0.058451 3.469 0.001
L1.Oberösterreich 0.263513 0.057481 4.584 0.000
L1.Salzburg 0.021067 0.028481 0.740 0.459
L1.Steiermark -0.025491 0.037781 -0.675 0.500
L1.Tirol 0.070975 0.029794 2.382 0.017
L1.Vorarlberg 0.058080 0.026965 2.154 0.031
L1.Wien -0.052380 0.051857 -1.010 0.312
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.018065 0.076552 0.134876 0.129623 0.042651 0.070292 0.004255 0.173104
Kärnten 0.018065 1.000000 -0.054789 0.129138 0.046497 0.069812 0.456431 -0.093749 0.095376
Niederösterreich 0.076552 -0.054789 1.000000 0.281658 0.080968 0.270438 0.013747 0.147254 0.246979
Oberösterreich 0.134876 0.129138 0.281658 1.000000 0.176380 0.288473 0.159695 0.116326 0.137317
Salzburg 0.129623 0.046497 0.080968 0.176380 1.000000 0.126312 0.055112 0.108991 0.049324
Steiermark 0.042651 0.069812 0.270438 0.288473 0.126312 1.000000 0.127801 0.087727 -0.025890
Tirol 0.070292 0.456431 0.013747 0.159695 0.055112 0.127801 1.000000 0.041634 0.117235
Vorarlberg 0.004255 -0.093749 0.147254 0.116326 0.108991 0.087727 0.041634 1.000000 -0.047435
Wien 0.173104 0.095376 0.246979 0.137317 0.049324 -0.025890 0.117235 -0.047435 1.000000